package com.zhuzi.controller;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author zhuzi
 * 2022/10/31 16:19
 */
@Slf4j
@RestController
//@RequestMapping("api")
public class ApiController {

    @PostMapping("/gather")
    public String gather(@RequestBody ReqBodyDTO context) {
        log.info("接收到的请求数据[{}]", context);

        return LocalDateTime.now().toString();
    }

    @PostMapping("/gathers")
    public String gathers(@RequestBody String context) {
        log.info("接收到的请求数据[{}]", context);

        ReqBodyDTO reqBodyDTO = JSON.parseObject(context, ReqBodyDTO.class);
        System.out.println(reqBodyDTO);
        return LocalDateTime.now().toString();
    }

    @Data
    @Accessors(chain = true)
    public static class ReqBodyDTO {
        private String content;
        private String msgType;
    }
}
